/*
 * This file is part of Euphrat.
 *
 * Copyright © 2012 Bart Verhoeven
 *
 * Euphrat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Euphrat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Euphrat. If not, see <http://www.gnu.org/licenses/>.
 */
package org.euphrat.client.service.login;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * The login information of the current user.
 *
 * @author Bart Verhoeven
 */
public class LoginContext implements IsSerializable {

  /**
   * The login state of a user.
   */
  public static enum State {
    /** User is logged in. */
    LOGGED_IN,
    /** User is logged out. */
    LOGGED_OUT,
    /** Login requested. */
    LOGIN_REQUESTED,
    /** Login request failed. */
    LOGIN_FAILED
  }

  /** User's nickname. */
  private String nickname;
  /** User's email address. */
  private String emailAddress;
  /** Is the user an admin. */
  private boolean isAdmin;
  /** User's login state. */
  private State state;
  /** Login URL. */
  private String loginURL;
  /** Logout URL. */
  private String logoutURL;

  /**
   * Creates a new login context. Initial state is logged out.
   */
  public LoginContext() {
    state = State.LOGGED_OUT;
  }

  /**
   * Returns the nickname of the user. Possibly {@code null}.
   *
   * @return the user's nickname
   */
  public String getNickname() {
    return nickname;
  }

  /**
   * Changes the nickname of the user.
   *
   * @param nickname the user's new nickname
   */
  public void setNickname(String nickname) {
    this.nickname = nickname;
  }

  /**
   * Returns the email address of the user. Possibly {@code null}.
   *
   * @return the user's email address
   */
  public String getEmailAddress() {
    return emailAddress;
  }

  /**
   * Changes the email address of the user.
   *
   * @param emailAddress the user's new email address
   */
  public void setEmailAddress(String emailAddress) {
    this.emailAddress = emailAddress;
  }

  /**
   * Returns whether the user is an administrator.
   *
   * @return true if the user is an administrator
   */
  public boolean isAdmin() {
    return isAdmin;
  }

  /**
   * Changes whether the user is an administrator.
   *
   * @param isAdmin whether the user is an administrator
   */
  public void setAdmin(boolean isAdmin) {
    this.isAdmin = isAdmin;
  }

  /**
   * Returns the login state of the user
   *
   * @return the user's login state
   */
  public State getLoginState() {
    return state;
  }

  /**
   * Changes the login state of the user.
   *
   * @param state the user's new login state
   */
  public void setLoginState(State state) {
    this.state = state;
  }

  /**
   * Returns a URL to the login page. Possibly {@code null}.
   *
   * @return a URL to to the login page
   */
  public String getLoginURL() {
    return loginURL;
  }

  /**
   * Changes the URL to the login page.
   *
   * @param loginURL the new login url
   */
  public void setLoginURL(String loginURL) {
    this.loginURL = loginURL;
  }

  /**
   * Returns a URL to the logout page. Possibly {@code null}.
   *
   * @return a URL to the logout page
   */
  public String getLogoutURL() {
    return logoutURL;
  }

  /**
   * Changes the URL to the logout page. Possibly {@code null}.
   *
   * @param logoutURL the new logout url
   */
  public void setLogoutURL(String logoutURL) {
    this.logoutURL = logoutURL;
  }
}
